import pymysql

db = pymysql.connect(host='localhost', port=3306, user='root', passwd='123456', database='test_123', charset='utf8')

# 创建游标
cur = db.cursor()

try:
    # 插入操作
    sql = "insert into table1 values \
          (100,'Jank',28,'1994-12-12');"
    cur.execute(sql)

    # 修改操作
    sql = "update table1 set age=18 where name = 'Frank';"
    cur.execute(sql)

    # 删除操作
    sql = "delete from table1 where age>35;"
    cur.execute(sql)

    db.commit()

except Exception as e:
    db.rollback()
    print("Failed:", e)

cur.close()
db.close()
